<template>
	<view class="classify-wrapper wrapperLayer borderBox">
		<view class="backTitlebar-wrapper colRange borderBox">
			<view class="fixedBox" style="background-color: #FE3A33;">
				<view class="topbox"></view>
				<view class="headerNavigationbar rowRangeAve borderBox">
					<view class="backIcon rowRangeStart">
					</view>
					<view class="pageTitle">
						超级分类
					</view>
					<view class="emptybox rowCenterEnd" >
						
					</view>
				</view>
			</view>
			<view class="placeBox">
				<view class="topbox"></view>
				<view class="placeemptybox">
				</view>
			</view>
		</view>
		<view class="category-list" :style="{ 'top': topheight + 'px' }">
			<!-- 左侧一级分类 -->
			<scroll-view scroll-y="true" class="left" :style="{ 'top': leftheight + 'px' }">
				<view class="row" v-for="(category, index) in categoryList" :key="category.cid" :class="[category.cid == showCategoryIndex ? 'on' : '']"
				 @click="showCategory(category.cid)">
					<view class="text">
						<view class="block"></view>
						{{ category.main_name }}
					</view>
				</view>
			</scroll-view>
			<!-- 右侧二级分类 -->
			<scroll-view scroll-y="true" class="right">
				<view class="category" v-for="(category, index) in categoryList" :key="index" v-show="category.cid == showCategoryIndex">
					<view v-for="(box, i) in category.data" :key="i">
						<view style="text-align: center">
							<text style="color: gainsboro">—</text>
							<text style="color: #000000;margin-right: 8px;margin-left: 8px">{{ box.next_name }}</text>
							<text style="color: gainsboro">—</text>
						</view>
						<view class="list" v-if="box.info.length>0" >
							<view class="box" v-for="(item, i1) in box.info" :key="i1">
								<image  @click="toCategory(item.son_name)" :src="item.imgurl" lazy-load="xxx"></image>
								<view class="text">{{ item.son_name }}</view>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>
<script>
	export default {
		components: {
			
		},
		data() {
			return {
				topheight:0,
				leftheight:0,
				showCategoryIndex: 1,
				headerPosition: 'fixed',
				categoryList: []
			};
		},
		onPageScroll(e) {
			if (e.scrollTop >= 0) {
				this.headerPosition = 'fixed';
			} else {
				this.headerPosition = 'absolute';
			}
		},
		onReady() {
			this.getTopheight()
		},
		onShow(){

		},
		onLoad() {
			this.getSuperClassifys();
		},
		methods: {
			getTopheight(){
				// 获取顶部高度
				uni.createSelectorQuery().in(this).select('.backTitlebar-wrapper').boundingClientRect(data => {
					console.log("得到布局位置信息" + JSON.stringify(data));
					this.topheight = data.height;
					// #ifdef APP-PLUS
						this.leftheight = data.height - 30;
					// #endif
					// #ifdef  H5
						this.leftheight = data.height;
					// #endif
				}).exec();
			},
			//超级分类
			getSuperClassifys(){
				this.$u.api.superClassifys().then(res => {
					if (res.code == 1){
						this.categoryList = res.general_classify;
					}
				});
			},
			//分类切换显示
			showCategory(index) {
				this.showCategoryIndex = index;
			},
			toCategory(name) {
				uni.navigateTo({
					url: '/pages/search/result?searchText=' + name
				})
			}
		}
	};
</script>
<style lang="scss">
	
	.classify-wrapper {
		width: 750rpx;
	}
	
		.backTitlebar-wrapper {
			.placeBox {
				.placeemptybox {
					height: 90rpx;
				}
			}
			.fixedBox {
				width: 100%;
				position: fixed;
				top: 0;
				left: 0;
				z-index: 100;

				.headerNavigationbar {
					width: 100%;
					height: 90rpx;
					padding: 0 32rpx;

					.backIcon {
						width: 60rpx;
						height: 32rpx;
						z-index: 1;

						image {
							width: 17rpx;
							height: 32rpx;
						}
					}

					.pageTitle {
						font-size: 32rpx;
						font-weight: 500;
						color: #FFFFFF;
					}

					.emptybox {
						width: 60rpx;
						height: 32rpx;

						.cleanAll {
							font-size: 32rpx;
							color: #FFFFFF;
						}
					}
				}
			}
		}
		
	.status {
		width: 100%;
		height: 0;
		position: fixed;
		z-index: 10;
		background-color: #fff;
		top: 0;
		/*  #ifdef  APP-PLUS  */
		height: var(--status-bar-height); 
		/*  #endif  */
	}

	.category-list {
		width: 100%;
		background-color: #fff;
		display: flex;
		.left,
		.right {
			/*  #ifdef  APP-PLUS  */
			top: var(--status-bar-height);
			/*  #endif  */
			bottom: 0upx;
		}

		.left {
			/*  #ifdef  APP-PLUS  */
			margin-top: var(--status-bar-height);
			/*  #endif  */
			position: fixed;
			width: 24%;
			left: 0upx;
			background-color: #f2f2f2;

			.row {
				width: 100%;
				height: 90upx;
				display: flex;
				align-items: center;

				.text {
					width: 100%;
					position: relative;
					font-size: 28upx;
					display: flex;
					justify-content: center;
					color: #3c3c3c;

					.block {
						position: absolute;
						width: 0upx;
						left: 0;
					}
				}

				&.on {
					height: 100upx;
					background-color: #fff;

					.text {
						font-size: 30upx;
						font-weight: 600;
						color: #2d2d2d;

						.block {
							width: 10upx;
							height: 80%;
							top: 10%;
							background-color: #f06c7a;
						}
					}
				}
			}
		}

		.right {
			margin-left: 24%;
			width: 76%;
			left: 24%;

			.category {
				width: 94%;
				padding: 20upx 3%;

				.banner {
					width: 100%;
					height: 24.262vw;
					border-radius: 10upx;
					overflow: hidden;
					box-shadow: 0upx 5upx 20upx rgba(0, 0, 0, 0.3);

					image {
						width: 100%;
						height: 24.262vw;
					}
				}

				.list {
					margin-top: 40upx;
					width: 100%;
					display: flex;
					flex-wrap: wrap;

					.box {
						width: calc(65.44vw / 3);
						margin-bottom: 30upx;
						display: flex;
						justify-content: center;
						align-items: center;
						flex-wrap: wrap;

						image {
							width: 60%;
							height: calc(71.44vw / 3 * 0.6);
						}

						.text {
							margin-top: 5upx;
							width: 100%;
							display: flex;
							justify-content: center;
							font-size: 26upx;
						}
					}
				}
			}
		}
	}
</style>
